﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Smartec.Accounts.Camel.AMS.Model.Entities;

namespace Smartec.Accounts.Camel.AMS.Model.Repository
{
    internal static class PictureRepository
    {
        //
        // Query Methods

        public static PagedList<Picture> GetPictures(int pageIndex, int pageSize)
        {
            var query = from p in AMSObjectContextHelper.CurrentObjectContext.Pictures
                        orderby p.ID descending
                        select p;
            var pics = new PagedList<Picture>(query, pageIndex, pageSize);
            return pics;
        }

        public static Picture GetPicture(int id)
        {
            return AMSObjectContextHelper.CurrentObjectContext.Pictures.SingleOrDefault(o => o.ID == id);
        }

        //
        // Insert/Delete Methods

        public static void Add(Picture picture)
        {
            AMSObjectContextHelper.CurrentObjectContext.Pictures.AddObject(picture);
        }

        public static void Delete(Picture picture)
        {
            AMSObjectContextHelper.CurrentObjectContext.Pictures.DeleteObject(picture);
        }


        //
        // Persistence 

        public static void Save()
        {
            AMSObjectContextHelper.CurrentObjectContext.SaveChanges();
        }

        // Helper Methods
    }
}
